package com.studyyoun.android.androidcommonbaselibrary.fragment;

/**
 * Created by androidlongs on 17/7/14.
 * 站在顶峰，看世界
 * 落在谷底，思人生
 */

import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;


/**
 * CommonBaseActivity Base基类封装
 */

public abstract class CommonBaseFragment extends Fragment {


    protected Context mContext;
    protected Handler mHandler = new Handler(Looper.getMainLooper());

    protected View mItemView;
    protected float mScaledDensity;
    protected int mScreenHeightPixels;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
        mItemView = inflater.inflate(getCommonLayoutId(), null);
        return mItemView;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        mContext = this.getActivity().getApplicationContext();
        mScaledDensity = mContext.getResources().getDisplayMetrics().scaledDensity;
        mScreenHeightPixels = mContext.getResources().getDisplayMetrics().heightPixels;
        commonInitView(mItemView);
        commonFunction();
        mHandler.postDelayed(new Runnable() {
            @Override
            public void run() {
                commonDelayFunction();
            }
        }, 200);


    }

    //获取布局ID
    protected abstract int getCommonLayoutId();

    //初始化控件
    protected abstract void commonInitView(View view);

    //常用功能 处理
    protected abstract void commonFunction();

    //延时常用功能 处理
    protected abstract void commonDelayFunction();



}
